import { fileURLToPath, URL } from 'node:url'
import { resolve } from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

const pathResolve = (dir: string): any => {
  return resolve(__dirname, '.', dir);
};
// https://vite.dev/config/
export default defineConfig({
  base: './',
  plugins: [
    vue({
      template: {
        compilerOptions: {
          isCustomElement: (tag) => false
        }
      }
    }),
    vueDevTools(),
  ],
  esbuild: {
    target: 'es2015'
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),      
      '/@node_modules/': pathResolve('./node_modules'),
    },
  },
  server: {
    open: true,//启动项目自动弹出浏览器
    port: 8000,
    proxy: {
      '/api': {
        //target: 'http://10.1.6.130',
       target: 'http://localhost:3000',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '/api') // 不可以省略rewrite
      },
       '/icons': {
      target: 'http://10.1.6.130',
       //  target: 'http://localhost:3000',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/icons/, '/icons') // 不可以省略rewrite
      },
       '/stutasks': {
      target: 'http://10.1.6.130',
       //  target: 'http://localhost:3000',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/stutasks/, '/stutasks') // 不可以省略rewrite
      }
    }
  }
})
